import { Promise } from 'es6-promise'
import { convertParams, convertRequestURL, localInfo, getQueryString, Storage ,getOS} from '../utils/utils'
import  store  from '../vuex/store'
import  { showLoading, hideLoading, setMsgTip, setUserId, setCity, setNeedLogin, setSessionId }  from '../vuex/actions'
import parser from 'ua-parser-js'


const _parser = new parser();

// console.log(_parser.getDevice())
const os = _parser.getOS().name
const osVersion = _parser.getOS().version
const model = _parser.getDevice().model
const manufacturer = _parser.getDevice().vendor
const windowHeight = $(window).height()
const windowWidth = $(window).width()


// alert(deviceDetailStr)
// errorCodeHandle
const errorCodeHandle = (resp,reject,unTip,nullTip,time)=>{
    if(resp.code){
        if(resp.code == 204){
            setMsgTip(store,{
                text:resp.msg,
                type:'error',
                time:time || 3000
            })
            reject(new Error(resp.msg))
            return true
        }
        else if(resp.code == 401 || resp.code == 23003){
            // console.log(store)
            if(!unTip){
                setMsgTip(store,{
                    text:resp.msg,
                    type:'error'
                })
            }
            setNeedLogin(store, true)
            setSessionId(store, '')
            reject(new Error(resp.msg))
            return true
        }
        else if(resp.code == 23002){
            // console.log(store)
            setMsgTip(store,{
                text:resp.msg,
                type:'error'
            })
            setNeedLogin(store, true)
            reject(new Error(resp.msg))
            return true
        }
        else if( resp.code == 23004 ){
            setMsgTip(store,{
                text:resp.msg,
                type:'error'
            })
            setNeedLogin(store, true)
            reject(new Error(resp.msg))
            return true
        }
        else{
            if(!unTip){
                setMsgTip(store, {
                    text:resp.msg,
                    type:'warn',
                    time:time || 3000
                })
            }
            reject(new Error(resp.msg))
            return true
        }
    }
    if(nullTip){
        if(!resp.data){
            setMsgTip(store, {
                text:resp.msg,
                type:'warn'
            })
            reject(new Error(resp.msg))
            return
        }
    }
    return false
}

// errorRequestHandle
const errorRequestHandle = (text,reject,noTip)=>{
    if(!noTip){
        setMsgTip(store,{
            text:'网络繁忙，请稍后再试',
            type:'error'
        })
    }
    reject(new Error(text));
}

const loginApi = {
    checkExist(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/checkExist"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求判断手机号是否注册失败',reject)
                }
            });
        })
    },
    
    register(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/register"),
                data:_.merge({
                    type:'H5'
                },params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp, reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('注册失败',reject)
                }
            });
        })
    },
    checkUserByMobile(params) {
        return new Promise(function (resolve, reject) {
            $.ajax({
                type: "post",
                url: convertRequestURL("user/checkUserByMobile"),
                data: params,
                dataType: "json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp, reject)
                    if (isError) return

                    let data = resp.data
                    resolve(data)
                },
                error() {
                    errorRequestHandle('验证失败', reject)
                }
            });
        })
    },
    login(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/login"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return
                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('注册失败',reject)
                }
            });
        })
    },
    checkBizRole(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/checkBizRole"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求判断角色失败',reject)
                }
            });
        })
    },
    logout(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/logout"),
                data:_.merge({
                    type:'H5'
                },params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store, {
                        text:'退出登录成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('退出登录失败',reject)
                }
            });
        })
    },
    sendSms(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("sms/sendSms"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store, {
                        text:'发送验证码成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('发送验证码失败',reject)
                }
            });
        })
    },
}


const userApi = {
    setBizRole(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/setBizRole"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求设置角色失败',reject)
                }
            });
        })
    },
    userStatus(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/userStatus"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求用户状态失败',reject)
                }
            });
        })
    },
    main(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/main"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求账户信息失败',reject)
                }
            });
        })
    },
    mine(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/userInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求用户信息失败',reject)
                }
            });
        })
    },
    limitDescription(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("cashOut/limitDescription"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求限额说明失败',reject)
                }
            });
        })
    },
    config(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/config"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    console.log(resp);
                    if(isError) return

                    let data = resp.data
                    window.localStorage.helpUrl = data.helpUrl
                    window.localStorage.extendDays = JSON.stringify(data.extendDays)
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求配置信息失败',reject)
                }
            });
        })
    },
    login(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/login"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store, {
                        text:'登录成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('登录失败',reject)
                }
            });
        })
    },
    logout(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/loginOut"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store, {
                        text:'退出登录成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('退出登录失败',reject)
                }
            });
        })
    },
    sendSms(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/sendLoginCode"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store, {
                        text:'发送验证码成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('发送验证码失败',reject)
                }
            });
        })
    },
    checkLoginPassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/checkLoginPassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    if(data.right == false){
                        setMsgTip(store, {
                            text:'校验登录密码失败',
                            type:'fail'
                        })
                    }
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求校验登录密码失败',reject)
                }
            });
        })
    },
    checkTradePassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/checkTradePassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    if(data.right == false){
                        setMsgTip(store, {
                            text:'校验交易密码失败',
                            type:'fail'
                        })
                    }
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求校验交易密码失败',reject)
                }
            });
        })
    },
    setTradePassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/setTradePassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    // if(data.right == true){
                    //     setMsgTip(store, {
                    //         text:'设置交易密码失败',
                    //         type:'fail'
                    //     })
                    // }
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求设置交易密码失败',reject)
                }
            });
        })
    },
    hadSetTradePassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/hadSetTradePassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    // if(data.right == true){
                    //     setMsgTip(store, {
                    //         text:'设置交易密码失败',
                    //         type:'fail'
                    //     })
                    // }
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求是否已经设置交易密码失败',reject)
                }
            });
        })
    },
    forgotLoginPassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/forgotLoginPassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求重置登录密码失败',reject)
                }
            });
        })
    },
    forgotTradePassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/forgotTradePassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求重置交易密码失败',reject)
                }
            });
        })
    },
    getInfo(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/info"),
                cache:false,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求用户信息失败',reject)
                }
            });
        })
    },
    getBalance(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("account/getBalance"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求余额失败',reject)
                }
            });
        })
    },
    recharge(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("charge/charge"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求充值失败',reject)
                }
            });
        })
    },
    cashOut(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("cashOut/cashOut"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求体现失败',reject)
                }
            });
        })
    },
    updateLoginPassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/updateLoginPassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data

                    setMsgTip(store, {
                        text:'更新登录密码成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求更新登录密码失败',reject)
                }
            });
        })
    },
    updateTradePassword(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/updateTradePassword"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求更新交易密码失败',reject)
                }
            });
        })
    },
    quota(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/quota"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求我的额度失败',reject)
                }
            });
        })
    },
    loanInInfo(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("borrow/myBorrowInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求借入详情失败',reject)
                }
            });
        })
    },
    loanOutInfo(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/myLendInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借出详情失败',reject)
                }
            });
        })
    },
    remindRepay(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("repayPlan/remindRepay"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求催收还款失败',reject)
                }
            });
        })
    },
    waitRepayInfo(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("repayPlan/waitRepayInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求待还信息失败',reject)
                }
            });
        })
    },
    waitReceiveInfo(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("repayPlan/waitReceiveInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求待收信息失败',reject)
                }
            });
        })
    },
    repayPlan(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("repayPlan/repayPlan"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求还款计划失败',reject)
                }
            });
        })
    },
    cashOutInfo(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("cashOut/info"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求提现信息失败',reject)
                }
            });
        })
    },
    realNameAuth(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/submitRealNameAuthenticationV2"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求实名认证失败',reject)
                }
            });
        })
    },
    canUnbundlingBankcard(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/canUnbundlingBankcard"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求是否可以解绑银行卡失败',reject)
                }
            });
        })
    },
    unbundlingBankcard(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("user/unbundlingBankcard"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求解绑银行卡失败',reject)
                }
            });
        })
    },


}

const loanApi = {
    info(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("loan/info"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借款申请信息失败',reject)
                }
            });
        })
    },
    apply(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("loan/apply"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借款申请失败',reject)
                }
            });
        })
    },
}

const storageApi = {
    upload(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("upload/upload"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求上传接口失败',reject)
                }
            });
        })
    },
    uploadBase64(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("upload/upload"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,'','',10000)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求上传接口失败',reject)
                }
            });
        })
    }
}

const loanOutApi = {
    
    main(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/main"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求出借页面失败',reject)
                }
            });
        })
    },
    
    viewRecord(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/showBrowseRecord"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求显示浏览记录失败',reject)
                }
            });
        })
    },
    
    paidRecord(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/showConsumptionRecord"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求消费记录失败',reject)
                }
            });
        })
    },
    addBrowseRecord(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/addBrowseRecord"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求添加浏览记录失败',reject)
                }
            });
        })
    },
    setRead(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/setRead"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求设置已读失败',reject)
                }
            });
        })
    },
    myPublishLending(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/myPublishLending"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求未处理最多的正在发布失败',reject)
                }
            });
        })
    },

    lendRecommend(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/recommendLendList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求推荐列表失败',reject)
                }
            });
        })
    },
    lendPlanList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/lendPlanList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求我的出借计划失败',reject)
                }
            });
        })
    },
    borrowListSquare(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("borrow/recommendBorrowList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求求借款人失败',reject)
                }
            });
        })
    },
    lendListSquare(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/recommendLendList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求发现出借人失败',reject)
                }
            });
        })
    },
    myList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/lendPlanList"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求我的出借列表失败',reject)
                }
            });
        })
    },
    allList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/allPlanList"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求全部出借列表失败',reject)
                }
            });
        })
    },
    detailOther(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/detail"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求出借详情失败',reject)
                }
            });
        })
    },
    rejectApply(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/rejectApply"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data

                    setMsgTip(store,{
                        text:'拒绝申请成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求拒绝申请失败',reject)
                }
            });
        })
    },
    addRemark(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/addRemark"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data

                    setMsgTip(store,{
                        text:'保存备注成功',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求保存备注失败',reject)
                }
            });
        })
    },
    userInfo(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("lend/userInfo"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求出借人信息失败',reject)
                }
            });
        })
    },
    close(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/close"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    setMsgTip(store,{
                        text:'关闭出借成功',
                        type:'success'
                    })

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求关闭出借失败',reject)
                }
            });
        })
    },
    open(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/open"),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    setMsgTip(store,{
                        text:'重新发布出借成功',
                        type:'success'
                    })

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求重新发布出借失败',reject)
                }
            });
        })
    },
    mine(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("user/userInfo"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求用户信息失败',reject)
                }
            });
        })
    },
    publish(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/publish"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求发布出借失败',reject)
                }
            });
        })
    },
    lendToIt(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/lendToIt"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借给TA失败',reject)
                }
            });
        })
    },
    lendRedPoint(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("lend/lendRedPoint"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求失败',reject)
                }
            });
        })
    },
}
const contactApi = {
    list(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/list"),
                // data:{
                //     // pageSize:
                // },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求联系人列表失败',reject)
                }
            });
        })
    },
    payFee(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/payFee"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求支付中介失败',reject)
                }
            });
        })
    },
    im(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/im"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求IM信息失败',reject)
                }
            });
        })
    },
    redhot(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/contactRedPoint"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求是否有新联系人失败',reject)
                }
            });
        })
    },
    borrowDetail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/borrowDetail"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求负债详情失败',reject)
                }
            });
        })
    },
    borrowSuccessList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/borrowSuccessList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借入款详细失败',reject)
                }
            });
        })
    },
    add(params,share){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/add"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    if(!share){
                        let isError = errorCodeHandle(resp,reject)
                        if(isError) return
                    }
                    else{
                        if(resp.code == 400){
                            resolve(resp)
                            return
                        }
                    }

                    let data = resp.data
                    // setMsgTip(store,{
                    //     text:'添加联系人成功',
                    //     type:'success'
                    // })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求添加联系人失败',reject)
                }
            });
        })
    },
    apply(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/applyAdd"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    setMsgTip(store,{
                        text:'发送申请成功！',
                        type:'success'
                    })
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求申请添加联系人失败',reject)
                }
            });
        })
    },
    agree(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/agreeApply"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求同意联系人申请失败',reject)
                }
            });
        })
    },
    applyList(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/applyList"),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data

                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求联系人申请列表失败',reject)
                }
            });
        })
    },
    detail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/detail"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求联系人详情失败',reject)
                }
            });
        })
    },
    loanInList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/borrowPlanList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借款计划失败',reject)
                }
            });
        })
    },
    loanOutList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/lendPlanList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求出借计划失败',reject)
                }
            });
        })
    },
    search(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/search"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求搜索联系人失败',reject)
                }
            });
        })
    },
    delete(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("contact/deleteContact"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求删除联系人失败',reject)
                }
            });
        })
    },
    remark(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/addRemarks"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求备注联系人失败',reject)
                }
            });
        })
    },
    judge(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("contact/judge"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求判断联系人失败',reject)
                }
            });
        })
    },
}

const messageApi = {
    list(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("message/list"),
                // data:{
                //     // pageSize:
                // },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求消息列表失败',reject)
                }
            });
        })
    },
    typeList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("message/typeList"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借条消息列表失败',reject)
                }
            });
        })
    },
    detail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("message/detail"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求消息详情失败',reject)
                }
            });
        })
    },
    setRead(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("message/setRead"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求消息设置已读失败',reject)
                }
            });
        })
    },
    unReadList(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL("message/unReadList"),
                // data:{
                //     // pageSize:
                // },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data


                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求未读消息列表失败',reject)
                }
            });
        })
    },
}

const reportApi = {
    carrier51gjj(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('carrier/51gjj/query'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求信用信息失败',reject)
                }
            });
        })
    },
    info(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/info'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求信用信息失败',reject)
                }
            });
        })
    },
    getImpl(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/getImpl'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求运营商第三方选择失败',reject)
                }
            });
        })
    },
    task51(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('carrier/51/crawler/task'),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data.uuid
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求提交任务失败',reject)
                }
            });
        })
    },
    vcode51(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL(`carrier/51/crawler/task/vcode`),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求提交验证码失败',reject)
                }
            });
        })
    },
    status51(params){
        return new Promise(function(resolve, reject){
            let pollin = ()=>{
                $.ajax({
                    type:"post",
                    url: convertRequestURL(`carrier/51/crawler/status`),
                    data:params,
                    dataType:"json",
                    success: (resp) => {
                        let isError = errorCodeHandle(resp,reject)
                        if(isError) return

                        let data = resp.data

                        if(data.phase == "CRAWL" && data.type == 'DOING'){
                            resolve({
                                type:'crawl',
                                info:data.resultDetail
                            })
                            return
                        }

                        if(!data.finished && data.type!='WAIT_CODE'){
                            setTimeout(()=>{
                                pollin()
                            },6000)
                            return
                        }

                        switch(data.type){
                            case 'WAIT_CODE':
                                let codeType = data.code.type
                                setMsgTip(store, {
                                    text:data.description,
                                    type:'info',
                                    time:3000
                                })
                                if(codeType == 'img'){
                                    let codeInfo = {
                                        type:'img',
                                        info:`data:image/jpg;base64,${data.code.imgBase64Val}`
                                    }
                                    resolve(codeInfo)
                                    return
                                }
                                if(codeType == 'sms'){
                                    let codeInfo = {
                                        type:'sms',
                                        info:'请输入您收到的验证码',
                                    }
                                    resolve(codeInfo)
                                    return
                                }
                                break;
                            case 'DONE_SUCC':
                                resolve({
                                    type:'result',
                                    info:data.resultDetail
                                })
                                break;
                            case 'DONE_FAIL':
                                setMsgTip(store, {
                                    text:data.description,
                                    type:'error',
                                    time:3000
                                })
                                reject(new Error(data.description))
                                break;
                            default:
                                setMsgTip(store, {
                                    text:data.description,
                                    type:'error'
                                })
                                reject(new Error(data.description))
                        }

                    },
                    error(){
                        errorRequestHandle('请求状态失败',reject)
                    }
                })
            }
            pollin()
        })
    },
    boxTool(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/boxTool'),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求催收工具信息失败',reject)
                }
            });
        })
    },
    newest(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/newest'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求用户信用报告状态失败',reject)
                }
            });
        })
    },
    create(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('creditReport/create'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求创建信用报告失败',reject)
                }
            });
        })
    },
    detail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/detail'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求信用报告详情失败',reject)
                }
            });
        })
    },
    submitUserInfo(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('creditReport/userInfo/submit'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求提交个人信息失败',reject)
                }
            });
        })
    },
    submitZmxy(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('creditReport/credit/submit'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求提交芝麻信用失败',reject)
                }
            });
        })
    },
    getLoginRule(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("auth/mobile/getLoginRule"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求运营商登录规则失败',reject)
                }
            });
        })
    },
    operatorsLogin(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("auth/mobile/login"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求运营商登录信息失败',reject)
                }
            });
        })
    },
    submitMessageCode(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL("auth/mobile/submitMessageCode"),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    resolve(resp.data)
                },
                error(){
                    errorRequestHandle('请求运营商提交短信验证码失败',reject)
                }
            });
        })
    },
    submitJd(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('ec/jd/task'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求JD任务失败',reject)
                }
            });
        })
    },
    jdInput(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('ec/jd/input'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求JD提交验证码失败',reject)
                }
            });
        })
    },
    jdStatus(params){
        return new Promise(function(resolve, reject){
            let pollin = ()=>{
                $.ajax({
                    type:"get",
                    url: convertRequestURL('ec/jd/status'),
                    data:params,
                    dataType:"json",
                    success: (resp) => {
                        let isError = errorCodeHandle(resp,reject)
                        if(isError) return

                        let data = resp.data

                        if(data.status == 'TODO' || data.status=='DOING'){
                            setTimeout(()=>{
                                pollin()
                            },5000)
                            return
                        }
                        switch(data.status){
                            case 'WAIT_INPUT':
                                let codeType = data.input.type
                                setMsgTip(store, {
                                    text:'请输入验证码',
                                    type:'info'
                                })
                                if(codeType == 'IMG'){
                                    let codeInfo = {
                                        type:'img',
                                        info:data.input.value
                                    }
                                    resolve(codeInfo)
                                    return
                                }
                                if(codeType == 'SMS'){
                                    let codeInfo = {
                                        type:'sms',
                                        info:'请输入您收到的验证码'
                                    }
                                    resolve(codeInfo)
                                    return
                                }
                                break;
                            case 'DONE_SUCCESS':
                                setMsgTip(store, {
                                    text:'京东数据请求成功',
                                    type:'success'
                                })
                                resolve({
                                    type:'result',
                                    info:''
                                })
                                break;
                            case 'DONE_FAIL':
                                setMsgTip(store, {
                                    text:data.subMsg,
                                    type:'error',
                                    time:3000
                                })
                                reject(new Error(data.subMsg))
                                break;
                            case 'TIMEOUT':
                                setMsgTip(store, {
                                    text:data.subMsg,
                                    type:'error'
                                })
                                reject(new Error(data.subMsg))
                                break;
                            default:
                                setMsgTip(store, {
                                    text:data.subMsg,
                                    type:'error'
                                })
                                reject(new Error(data.description))
                        }
                        resolve(data)
                    },
                    error(){
                        errorRequestHandle('请求JD任务状态失败',reject)
                    }
                })
            }
            pollin()
        })
    },
}

const payApi = {
    pay(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('pay/doPay'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求支付失败',reject)
                }
            });
        })
    },
    payBankCard(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('pay/doPay'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求支付失败',reject)
                }
            });
        })
    },
}

const weixinApi = {
    getSignature(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('weixin/getSignature'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求微信签名失败',reject)
                }
            });
        })
    },
}
const receiptApi = {
    createReceipt(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/createReceipt'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求生成借条失败',reject)
                }
            });
        })
    },
    detail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/detail'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借条详情失败',reject)
                }
            });
        })
    },
    delete(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/delete'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求删除借条失败',reject)
                }
            });
        })
    },
    agree(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/confirm'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求同意借条失败',reject)
                }
            });
        })
    },
    complete(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/complete'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求完成借条失败',reject)
                }
            });
        })
    },
    return(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('receipt/return'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求退回借条失败',reject)
                }
            });
        })
    },
    agreement(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('receipt/agreement'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求借款协议失败',reject)
                }
            });
        })
    },
    receiptList(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('receipt/receiptList'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求我的借条失败',reject)
                }
            });
        })
    },
}
const allApi = {
    blacklist(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('blacklist/blacklistList'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求黑名单信息失败',reject)
                }
            });
        })
    },

    setRead(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('notice/setRead'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求设置已读失败',reject)
                }
            });
        })
    },
    
    noticeShow(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('notice/show'),
                cache:false,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求公告失败',reject)
                }
            });
        })
    },
    
    getList(url,params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL(url),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求列表失败',reject)
                }
            });
        })
    },
    partDetail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/partDetail'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求详情部分失败',reject)
                }
            });
        })
    },
    log(params){
        let value = params.e_v
        if(value){
            value = JSON.stringify(value)
            params.e_v = value
        }
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('log/'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求上报事件失败',reject)
                }
            });
        })
    },
}
const scoreApi = {
    
    getBalance(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('score/getBalance'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求请求余额失败',reject)
                }
            });
        })
    },
    calc(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('scoreCharge/calc'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求充值计算器失败',reject)
                }
            });
        })
    },

    charge(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('scoreCharge/charge'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求点券充值失败',reject)
                }
            });
        })
    },
    
    noticeShow(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('notice/show'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject,true)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求公告失败',reject)
                }
            });
        })
    },
    
    getList(url,params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL(url),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求列表失败',reject)
                }
            });
        })
    },
    partDetail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('creditReport/partDetail'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求详情部分失败',reject)
                }
            });
        })
    },
    onEvent(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('even/onEvent'),
                data:_.merge({
                    deviceId:store.state.localInfo.deviceId,
                    appName:'有借',
                    appPackage:'',
                    appPlatform:'H5',
                    appVersion:'',
                    screenHeight:windowHeight,
                    screenWidth:windowWidth,
                    lat:'',
                    lng:'',
                    osVersion:osVersion,
                    os:os,
                    manufacturer:manufacturer,
                    model:model,
                    eventTimestamp:+new Date(),
                    channel:getQueryString().channel
                },params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求上报事件失败',reject)
                }
            });
        })
    },
}

const bankcardApi = {
    list(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/cardList'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求银行卡列表失败',reject)
                }
            });
        })
    },
    setDefault(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/setDefault'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求设置默认失败',reject)
                }
            });
        })
    },
    unbind(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/unBind'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求删除银行卡失败',reject)
                }
            });
        })
    },
    change(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/change'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求更换银行卡失败',reject)
                }
            });
        })
    },
    getBankName(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/getBankName'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求卡号获取银行卡失败',reject)
                }
            });
        })
    },
    bindCard(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/card/bindCardInAuth'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求绑定银行卡失败',reject)
                }
            });
        })
    },
    add(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bankcard/addCard'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求添加银行卡失败',reject)
                }
            });
        })
    },
}

const indexApi = {
    banner(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"get",
                url: convertRequestURL('banner/get'),
                dataType:"json",
                data:params,
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('获取广告位图片失败',reject)
                }
            });
        })
    },
    bindClient(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('client/bindClient'),
                data:{
                    deviceCode:store.state.localInfo.deviceId,
                },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求绑定设备信息失败',reject)
                }
            });
        })
    },
    bindUser(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bindUser'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求绑定用户失败',reject)
                }
            });
        })
    },
    appConfigData(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('appConfigData'),
                data:{},
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求app首页配置信息失败',reject)
                }
            });
        })
    },
    add(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bankcard/addCard'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求添加银行卡失败',reject)
                }
            });
        })
    },
    change(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bankcard/change'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求更换银行卡失败',reject)
                }
            });
        })
    },
    unbind(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bankcard/unbind'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求解除绑定失败',reject)
                }
            });
        })
    },
}

const authApi = {
    zhimaAuthMANUAL(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                data:params,
                url: convertRequestURL('auth/zhimaAuthMANUAL'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求芝麻认证失败',reject)
                }
            });
        })
    },
    authItemList(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/authItemList'),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求认证项列表失败',reject)
                }
            });
        })
    },
    authItemStatus(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/authItemStatusByCode'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    if(data.status >= 30){
                        setMsgTip(store,{
                            text:'认证审核中，禁止修改信息',
                            type:'error',
                            time:3000
                        })
                    }
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求认证项进度失败',reject)
                }
            });
        })
    },
    identityInfoAuth(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/identityInfoAuth'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求身份认证失败',reject)
                }
            });
        })
    },
    basicInfoAuth(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                contentType:'application/json',
                url: convertRequestURL('auth/basicInfoAuth'),
                data:JSON.stringify(params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求个人信息认证失败',reject)
                }
            });
        })
    },
    jobInfoAuth(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                contentType:'application/json',
                url: convertRequestURL('auth/jobInfoAuth'),
                data:JSON.stringify(params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求工作信息认证失败',reject)
                }
            });
        })
    },
    contactInfoAuth(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                contentType:'application/json',
                url: convertRequestURL('auth/contactInfoAuth'),
                data:JSON.stringify(params),
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求紧急联系人认证失败',reject)
                }
            });
        })
    },
    zhimaAuthUrl(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('auth/zhimaAuthUrl'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求芝麻信用认证地址失败',reject)
                }
            });
        })
    },
}


const billApi = {
    cancelTransaction(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/cancelTransaction'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求取消交易失败',reject)
                }
            });
        })
    },
    confirmExtendAmount(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/confirmExtendAmount'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求展期金额确认失败',reject)
                }
            });
        })
    },
    promptExtend(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/promptExtend'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求延长交付时间失败',reject)
                }
            });
        })
    },
    currentBill(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/currentBill'),
                data:{
                    deviceCode:store.state.localInfo.deviceId,
                },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求当前账单记录失败',reject)
                }
            });
        })
    },
    historyBillList(){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/historyBillList'),
                data:{
                    deviceCode:store.state.localInfo.deviceId,
                },
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求历史账单记录失败',reject)
                }
            });
        })
    },
    billDetail(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/billDetail'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求账单详情失败',reject)
                }
            });
        })
    },
    promptRepay(params){
        return new Promise(function(resolve, reject){
            $.ajax({
                type:"post",
                url: convertRequestURL('bill/promptRepay'),
                data:params,
                dataType:"json",
                success: (resp) => {
                    let isError = errorCodeHandle(resp,reject)
                    if(isError) return

                    let data = resp.data
                    resolve(data)
                },
                error(){
                    errorRequestHandle('请求立即还款失败',reject)
                }
            });
        })
    },
}
export {
    indexApi,
    allApi,
    billApi,
    scoreApi,
    authApi,
    weixinApi,
    payApi,
    reportApi,
    loginApi,
    userApi,
    loanApi,
    loanOutApi,
    messageApi,
    contactApi,
    storageApi,
    receiptApi,
    bankcardApi
 }